package com.bac.rentmap.ad.flat.proccess;

import com.bac.rentmap.ad.flat.FlatAd;
import com.bac.rentmap.ad.flat.image.FlatImageType;
import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import org.springframework.beans.factory.annotation.Required;

import java.util.Map;

/**
 * Deletes {@link FratAds} older than <code>maxAgeInDays</code>. If not
 * configured deletes all ads.
 * 
 * @author Andrew Osipenko
 */
public class OldFlatAdProccessor extends AbstractOldItemProcessor<FlatAd> implements
        FlatAdProccessor {
    private BlobstoreService blobstoreService;

    protected void beforeDelete(FlatAd flatAd){
        super.beforeDelete(flatAd);
        for(Map.Entry<FlatImageType, BlobKey> entry: flatAd.getFlatImageBlobs().entrySet()){
            blobstoreService.delete(entry.getValue());
        }
    }
    @Override
    protected Class<FlatAd> getPersistentClass() {
        return FlatAd.class;
    }

    @Override
    protected String getDatePropertyName() {
        return "lastPublishingDate";
    }

    @Required
    public void setBlobstoreService(BlobstoreService blobstoreService) {
        this.blobstoreService = blobstoreService;
    }
}
